package UI.todos;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import static uiMain.bienRaizOk.ventana;

public class PanelCerrandoSesion extends JPanel {

    JProgressBar progressBar;
    JLabel label;

    public PanelCerrandoSesion() {
        super();

        this.setLayout(null);

        progressBar = new JProgressBar();
        this.add(progressBar).setBounds(190, 130, 300, 15);

        label = new JLabel("", SwingConstants.CENTER);
        this.add(label).setBounds(190, 110, 300, 25);

        new ControladorBarra().start();

    }

    class ControladorBarra extends Thread {

        int progreso = 0;

        @Override
        public void run() {
            label.setText("Limpiando cookies...");
            while (progreso < 100) {
                progreso += (int) 10 * Math.random();
                progressBar.setValue(progreso);
                if (progreso > 30 && progreso < 100) {
                    label.setText("Eliminando archivos temporales... (" + (progreso-30) + "/70)");
                }
                try {
                    this.sleep(60);
                } catch (InterruptedException ex) {
                    System.out.println(ex.getMessage());
                }
            }
            ventana.mostrarPantallaParaIniciarSesion();

        }
    }
}
